﻿Imports System.IO
Imports DevExpress.XtraEditors

Public Class HomePage
    Private constparam() As String = {"deskripsi", "logosekolah"}
    Private Sub Byte2Image(ByRef NewImage As Image, ByVal ByteArr() As Byte)
        '
        Dim ImageStream As MemoryStream
        Try

            If ByteArr.GetUpperBound(0) > 0 Then
                ImageStream = New MemoryStream(ByteArr)
                NewImage = Image.FromStream(ImageStream)
            Else
                NewImage = Nothing
            End If

        Catch ex As Exception

            NewImage = Nothing

        End Try

    End Sub
    Public Sub refreshdata()
        Dim dt As New DataTable
        If Utils.executeSP("proc_searchall", New Object() {"*", "videntitas", "deskripsi", ""}, dt) Then
            If Utils.RowExist(dt) Then
                FillData(dt)
            End If
        End If
    End Sub
    Private Sub FillData(ByVal dtin As DataTable)
        For Each Sctl As String In constparam
            Dim ctl As Control()
            ctl = Me.Controls.Find(Sctl, True)
            If ctl IsNot Nothing And ctl.Length > 0 Then
                If TypeOf ctl(0) Is MemoEdit Then
                    Dim ctlmemo As New MemoEdit
                    ctlmemo = CType(ctl(0), MemoEdit)
                    If IsDBNull(dtin(0)(Sctl)) Then
                        ctlmemo.Text = ""
                    Else
                        Dim rtb As New RichTextBox
                        rtb.Text = dtin(0)(Sctl)
                        ctlmemo.Lines = rtb.Lines
                        'MemoEdit1.Lines = ctlmemo.Lines
                    End If
                ElseIf TypeOf ctl(0) Is TextEdit Then
                    If IsDBNull(dtin(0)(Sctl)) Then
                        ctl(0).Text = ""
                    Else
                        ctl(0).Text = dtin(0)(Sctl)
                    End If
                ElseIf TypeOf ctl(0) Is PictureBox Then
                    Dim ctlimage As New PictureBox
                    ctlimage = CType(ctl(0), PictureBox)
                    If IsDBNull(dtin(0)(Sctl)) Then
                        ctlimage.Image = Nothing
                    Else
                        Dim img As Image
                        img = Nothing
                        Byte2Image(img, dtin(0)(Sctl))
                        ctlimage.Image = img
                        ctlimage.SizeMode = PictureBoxSizeMode.StretchImage
                    End If
                End If
            End If
        Next
    End Sub
    Private Sub HomePage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        refreshdata()
    End Sub
End Class
